from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import redirect, reverse, HttpResponse
from django.conf import global_settings, settings
from web01 import models


class UserMiddleWare(MiddlewareMixin):

    def process_request(self, request):
        is_login = request.session.get('is_login')
        if is_login:
            obj = models.UserInfo.objects.filter(pk=request.session['user_pk']).first()
            request.user_obj = obj
            return
        # url = request.path_info
        # return redirect("{}?url={}".format(reverse('login'), url))
